home *** CD-ROM | disk | FTP | other *** search
/ Click - International Series 1 / Click Jigsaw Puzzles: Ken Duncan.iso / mac / puzzles / Tranquility.dxr / 00234_file I-O xtra.ls < prev    next >
Encoding:
Text File  |  2002-11-11  |  4.4 KB  |  146 lines

  1. global allTogether, fit, piecesParts, allPieces, newConnect, start, totalPieces, tolerance, stageWide, stageTall, puzzleLayout, previewSprite, edgeMembers, showEdges, currentPuzzle, canRotate, isShockmachine, difficulty
  2.  
  3. on writeFile
  4.   filePath = the moviePath & "demoSaveFile"
  5.   fileText = member("user message").text
  6.   if fileText = EMPTY then
  7.     alert("Please enter a text message to save")
  8.     exit
  9.   end if
  10.   fileIOInstance = xtra("FileIO").new()
  11.   if not fileIOInstance.objectp then
  12.     alert("File IO Xtra missing")
  13.     exit
  14.   end if
  15.   fileIOInstance.createFile(filePath)
  16.   case fileIOInstance.status() of
  17.     0:
  18.       nothing()
  19.     (-122):
  20.       fileIOInstance.openFile(filePath, 0)
  21.       delete(fileIOInstance)
  22.       fileIOInstance.createFile(filePath)
  23.     otherwise:
  24.       alert("Error: " & fileIOInstance.error(fileIOInstance.status()))
  25.       exit
  26.   end case
  27.   fileIOInstance.openFile(filePath, 0)
  28.   fileIOInstance.writeString(fileText)
  29.   fileIOInstance.closeFile()
  30. end
  31.  
  32. on readFile
  33.   filePath = the moviePath & "demoSaveFile"
  34.   fileIOInstance = xtra("FileIO").new()
  35.   if not fileIOInstance.objectp then
  36.     alert("File IO Xtra missing")
  37.     exit
  38.   end if
  39.   fileIOInstance.openFile(filePath, 0)
  40.   if fileIOInstance.status() = 0 then
  41.     fileText = fileIOInstance.readFile()
  42.     fileIOInstance.closeFile()
  43.     member("file contents").text = fileText
  44.   else
  45.     member("file contents").text = "Error: " & fileIOInstance.error(fileIOInstance.status())
  46.   end if
  47. end
  48.  
  49. on getSystemFolder
  50.   put getOSDirectory()
  51. end
  52.  
  53. on savePuzzleFileIO
  54.   cursor(4)
  55.   beep()
  56.   the itemDelimiter = "."
  57.   preview = [:]
  58.   addProp(preview, sprite(previewSprite).visible, the rect of sprite previewSprite)
  59.   addProp(preview, sprite(previewSprite - 1).visible, the rect of sprite (previewSprite - 1))
  60.   addProp(preview, sprite(previewSprite - 2).visible, the rect of sprite (previewSprite - 2))
  61.   addProp(preview, sprite(previewSprite - 3).visible, the rect of sprite (previewSprite - 3))
  62.   addProp(preview, sprite(previewSprite - 4).visible, the rect of sprite (previewSprite - 4))
  63.   addProp(preview, sprite(previewSprite - 5).visible, the rect of sprite (previewSprite - 5))
  64.   pieces = [:]
  65.   thisSprite = 1
  66.   repeat while thisSprite <= totalPieces
  67.     addProp(pieces, (the member of sprite (thisSprite + 1)).number, the loc of sprite (thisSprite + 1))
  68.     thisSprite = 1 + thisSprite
  69.   end repeat
  70.   rotations = []
  71.   aPiece = 1
  72.   repeat while aPiece <= totalPieces
  73.     add(rotations, sprite(aPiece + 1).rotation)
  74.     aPiece = 1 + aPiece
  75.   end repeat
  76.   timeSoFar = the ticks - start
  77.   setupInfo = allTogether & TAB & fit & TAB & piecesParts & TAB & allPieces & TAB & totalPieces & TAB & preview & TAB & pieces & TAB & rotations & TAB & timeSoFar & TAB & canRotate & TAB & difficulty
  78.   writePuzzleFile(getOSDirectory() & currentPuzzle & ".txt", setupInfo)
  79.   cursor(0)
  80. end
  81.  
  82. on writePuzzleFile puzzFilePath, setupInfo
  83.   put puzzFilePath
  84.   filePath = puzzFilePath
  85.   fileText = setupInfo
  86.   fileIOInstance = xtra("FileIO").new()
  87.   if not fileIOInstance.objectp then
  88.     alert("File IO Xtra missing")
  89.     exit
  90.   end if
  91.   fileIOInstance.createFile(filePath)
  92.   case fileIOInstance.status() of
  93.     0:
  94.       nothing()
  95.     (-122):
  96.       fileIOInstance.openFile(filePath, 0)
  97.       delete(fileIOInstance)
  98.       fileIOInstance.createFile(filePath)
  99.     otherwise:
  100.       alert("Error: " & fileIOInstance.error(fileIOInstance.status()))
  101.       exit
  102.   end case
  103.   fileIOInstance.openFile(filePath, 0)
  104.   fileIOInstance.writeString(fileText)
  105.   fileIOInstance.closeFile()
  106. end
  107.  
  108. on getPuzzleFileIO puzzFilePath
  109.   filePath = puzzFilePath
  110.   fileIOInstance = xtra("FileIO").new()
  111.   if not fileIOInstance.objectp then
  112.     alert("File IO Xtra missing")
  113.     exit
  114.   end if
  115.   fileIOInstance.openFile(filePath, 0)
  116.   if fileIOInstance.status() = 0 then
  117.     fileText = fileIOInstance.readFile()
  118.     fileIOInstance.closeFile()
  119.     return fileText
  120.   else
  121.     return VOID
  122.   end if
  123. end
  124.  
  125. on deletePuzzleProgress
  126.   filePath = getOSDirectory() & currentPuzzle & ".txt"
  127.   fileIOInstance = xtra("FileIO").new()
  128.   if not fileIOInstance.objectp then
  129.     alert("File IO Xtra missing")
  130.     exit
  131.   end if
  132.   fileIOInstance.createFile(filePath)
  133.   case fileIOInstance.status() of
  134.     0:
  135.       fileIOInstance.openFile(filePath, 0)
  136.       delete(fileIOInstance)
  137.     (-122):
  138.       fileIOInstance.openFile(filePath, 0)
  139.       delete(fileIOInstance)
  140.     otherwise:
  141.       alert("Error: " & fileIOInstance.error(fileIOInstance.status()))
  142.       exit
  143.   end case
  144.   fileIOInstance = 0
  145. end
  146.